<template>
	<view class="cart-container" v-if="cart.length !== 0">
		<!-- 收货地址 -->
		<my-address></my-address>
		<!-- 购物车商品列表标题区 -->
		<view class="cart-title">
			<uni-icons type="shop" size='18'></uni-icons>
			<text class="cart">购物车</text>
		</view>
		<!-- 商品列表区域的基本结构 -->
		<uni-swipe-action>
			<block v-for="(goods,index) in cart" :key="index">
				<uni-swipe-action-item : :right-options="options"  @click="handleDeleteGoods(goods)">
					<my-goods
					:goods='goods' 
					isShowRadio 
					@click-radio="clickRadio" 
					@change-number="changeNumber"
					isShowNumber
					/>
				</uni-swipe-action-item>
			</block>
		</uni-swipe-action>
		<!-- 结算页面 -->
		<my-settle :cartInfo='cart'></my-settle>
	</view>
	<view v-else class="empty-img" :style="{height:vh+'px'}">
		<image src="/static/cart_empty@2x.png"></image>
		<text>空空如也</text>
	</view>
</template>

<script>
	import { mapActions,mapState,mapMutations,mapGetters } from 'vuex' 
	import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		data() {
			return {
				vh:0,
				options: [{
				      text: '删除', // 显示的文本内容
				      style: {
				        backgroundColor: '#C00000' // 按钮的背景颜色  
				      }
				    }]
			};
		},
		mixins:[badgeMix],
		computed: {
			...mapState({
				text: state => state.cart.text,
				cart:state =>state.cart.cartInfo
			}),
			...mapGetters(['total'])
		},
		onLoad(){
			const sysInfo = uni.getSystemInfoSync()
			//windowHeight 是可使用高度（去掉 toptab 和 tabber 剩下的高度)
			this.vh = sysInfo.windowHeight
		},
		methods:{
			...mapMutations(['addToCart','updateGoodsState','updateGoodsCount','deleteGoods']),
			
			clickRadio(e){
				this.updateGoodsState(e)
			},
			changeNumber(e){
				this.updateGoodsCount(e)
				this.handleTabBarBadge()
			},
			handleDeleteGoods(e){
				this.deleteGoods(e)
				this.handleTabBarBadge()
			},
			
		}
	}
</script>

<style lang="scss">
	.cart-title{
		display: flex;
		padding:8px;
		font-size:15px;
		border-bottom:1px solid #efefef;
		.cart{
			margin-left:10px;
		}
	}
.empty-img{
	// background-color: yellow;
   
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	image{
		width:100px;
		height:100px;
	}
	text{
		font-size:12px;
		color:gray;
		margin-top:15px;
	}
}
</style>
